﻿using Anke.SHManage.MSSQLDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class TimeAndCenterModeWebForm : System.Web.UI.Page
    {
        private string reportName;
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                this.ReportViewer1.LocalReport.EnableHyperlinks = true;
                InitPage();

            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }

        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();
        } 

        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.ToString("yyyy-MM-01 00:00:00");
            this.EndDate.Text = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");

            if (Request.QueryString["ReportName"] != null)
            {
                reportName = Request.QueryString["ReportName"];
                ViewState["reportName"] = reportName;
            }
            else
            {
                reportName = "InvoiceNumberAbnormal.rdlc";
                ViewState["reportName"] = reportName;
            }
        
            BindReportDataSource();
        }

        protected void BindReportDataSource()
        {

            DateTime start = Convert.ToDateTime(this.StartDate.Text);
            DateTime end = Convert.ToDateTime(this.EndDate.Text);
            string txtCenter = Convert.ToString(this.txtCenter.Text);
            string stationID = Convert.ToString(this.Station.Text);
            string start1 = start.ToString();
            string end1 = end.ToString();
            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/" + reportName);
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("StartTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("EndTime", end1);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed });
          
            I_InvoiceApplyDAL iadal = new I_InvoiceApplyDAL();
            switch (reportName)
            {
              
                //2016-4-12 新增统计发票异地使用情况
                case "InvoiceNumberAbnormal.rdlc":
                    this.Page.Title = "发票异地使用情况统计";
                    DataTable dt46 = iadal.getInvoiceNumberAbnormalUse(start, end, txtCenter, stationID);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt46));
                    break;
                default:
                    break;
            }
            this.ReportViewer1.LocalReport.Refresh();
        }

    }
}